﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/view.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="Workflow.Resource" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script type="text/javascript">
        function query() {
            var queryParams = $('#grid').datagrid('options').queryParams;

            queryParams.UserID = $('#UserID').val();
            queryParams.UserName = $('#UserName').val();
            queryParams.Group = $('#Group').combobox('getValue');



            $('#grid').datagrid('options').queryParams = queryParams;
            //alert($('#grid').datagrid('options').queryParams.UserID);
            $("#grid").datagrid('reload');
        }
        function actionFormatter(value, rowData, rowIndex) {

            var id = rowData.UserID;
            var p = "";
            if (rowData.IsValid) {
                p = " <img title=\"<%=Global.deactivate %>\" alt=\"<%=Global.deactivate %>\" src=\"../../Image/deactivate.gif\" onclick=\"ActiveUser('" + id + "')\" />";

            }
            else {
                p = " <img title=\"<%=Global.activate %>\" alt=\"<%=Global.activate %>\" src=\"../../Image/activate.gif\" onclick=\"ActiveUser('" + id + "')\" />";
            }
            var sp = "<a href=\"#\" onclick=\"DeleteUser('" + id + "')\">Delete</a>";
            var a = "  <img title=\"<%=Global.eidtuser %>\" alt=\"<%=Global.eidtuser %>\" src=\"../../Image/edit.gif\" onclick=\"UpdateUser('" + id + "')\" />"
            var d = " <img title=\"<%=Global.changepassword %>\" alt=\"<%=Global.changepassword %>\" src=\"../../Image/setPassword.gif\" onclick=\"changepassword('" + id + "')\" />"
           return p + '&nbsp;' + a + '&nbsp;' +  d;

        }
        function changepassword(id) {
            $('#hidChangePassId').val(id);
            $('#w').window('open');

        }
        function addUser() {
            window.location = '/User/Detail';
            return false;
        }
        function UpdateUser(id) {
            window.location = '/User/Detail/' + id;
            return false;
        }
        function DeleteUser(id) {
            $.messager.confirm('info', 'Are you confirm delete it?', function (r) {
                if (r) {
                    //alert(user_form);
                    $('#form').form('submit', {
                        url: '/User/DeleteUser/' + id,
                        success: function (data) {
                            eval('data=' + data);
                            if (data.Success) {
                                // _user_form.form('clear');
                                $.messager.alert('Info', data.Message, 'info');
                            } else {
                                $.messager.alert('Error', data.Message, 'error');
                            }
                            $("#grid").datagrid('reload');
                        },
                        onSubmit: function () {
                            //if (_user_form.valid())
                            return true;
                            // else
                            //    return false;
                        }
                    });
                }
            });

        }

        function ActiveUser(id) {

            $('#form').form('submit', {
                url: '/User/ActiveUser/' + id,
                success: function (data) {
                    eval('data=' + data);
                    if (data.Success) {
                        // _user_form.form('clear');
                        $.messager.alert('Info', data.Message, 'info');
                    } else {
                        $.messager.alert('Error', data.Message, 'error');
                    }
                    $("#grid").datagrid('reload');
                },
                onSubmit: function () {
                    //if (_user_form.valid())
                    return true;
                    // else
                    //    return false;
                }
            });
        }
        //关闭登录窗口
        function closePwd() {
            $('#w').window('close');
        }
        //修改密码
        function savePwd() {

            var $hidChangePassId = $('#hidChangePassId');
            var $newpass = $('#txtNewPass');
            var $rePass = $('#txtRePass');

            if ($newpass.val() == '') {
                $.messager.alert('<%=Global.InfoTitle%>', "<%=Global.inputpassword%>", 'warning');
                return false;
            }
            if ($rePass.val() == '') {
                $.messager.alert('<%=Global.InfoTitle%>', "<%=Global.reinputpassword%>", 'warning');
                return false;
            }

            if ($newpass.val() != $rePass.val()) {
                $.messager.alert('<%=Global.InfoTitle%>', "<%=Global.passworddifferent%>", 'warning');
                return false;
            }
            $.post('/User/EditPassword?newpass=' + $newpass.val() + '&id=' + $hidChangePassId.val(),
             function (data) {
                 eval('data=' + data);
                 closePwd();
                 if (data.Success) {

                     $.messager.alert('<%=Global.InfoTitle%>', data.Message, 'info');

                 } else {
                     $.messager.alert('<%=Global.ErrorTitle%>', data.Message, 'error');

                 }

                 $('#hidChangePassId').val("");
                 $('#txtNewPass').val("");
                 $('#txtRePass').val("");

             })

        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <form class="easyui-layout" method="post" id="form" name="form" style=" width:100%;height: 720px;">
       <div region="center" >
    <table id="grid" class="easyui-datagrid" style="width: 1050px; height: 350px" url="/User/GetUser"
        title="User" toolbar="#tb" singleselect="true" fit="true" fitcolumns="true" pagination="true"
        queryparams="{}" pageSize="20">
        <thead>
            <tr>
                <th field="UserID" width="160">
                    <%=Global.UserID%>
                </th>
                <th field="UserName" width="180">
                    <%=Global.username%>
                </th>
                <th field="Email" align="right" width="200">
                    <%=Global.Email%>
                </th>
                <th field="GroupName" width="100">
                    <%=Global.Group%>
                </th>
                <th field="RoleName" width="100">
                    <%=Global.Role%>
                </th>
                <th field="IsValid" align="center" width="80">
                      <%=Global.IsValid%>
                </th>
                <th field="action" width="200" align="center" formatter="actionFormatter">
                      <%=Global.Action%>
                </th>
            </tr>
        </thead>
    </table>
    <div id="tb" style="padding: 5px; height: auto">
        <div style="margin-bottom: 5px">
            <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="addUser();">
                 <%=Global.adduser%></a>
        </div>
        <div>
            <%=Global.UserID%>:
            <input id="UserID" style="width: 80px">
             <%=Global.username%>:
            <input id="UserName" style="width: 80px">
            <%=Global.Group%>:
            <input id="Group" url="/User/GetGroupList" class="easyui-combobox" style="width: 100px"
                    valuefield="GroupCode" textfield="GroupName" multiple="false" editable="false">
            <a href="#" class="easyui-linkbutton" iconcls="icon-search" onclick="query();">  <%=Global.Search%></a>
        </div>
    </div>
    </div>
    </form>
    <div id="w" class="easyui-window" title=" <%=Global.changepassword %>" collapsible="false" minimizable="false"
        maximizable="false" icon="icon-save" style="width: 300px; height: 180px; padding: 5px;
        background: #fafafa;" closed="true">
        <div class="easyui-layout" fit="true">
            <div region="center" border="false" style="padding: 10px; background: #fff; border: 1px solid #ccc;">
                <table cellpadding="3">
                    <input id="hidChangePassId" type="hidden" />
                    <tr>
                        <td>
                            <%=Global.newpassword %>：
                        </td>
                        <td>
                            <input id="txtNewPass" type="Password" class="txt01" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <%=Global.confirmpassword %>：
                        </td>
                        <td>
                            <input id="txtRePass" type="Password" class="txt01" />
                        </td>
                    </tr>
                </table>
            </div>
            <div region="south" border="false" style="text-align: right; height: 30px; line-height: 30px;">
                <a id="btnEp" class="easyui-linkbutton" icon="icon-ok" onclick="javascript: savePwd();">
                    <%=Global.ok %></a> <a id="btnCancel" class="easyui-linkbutton" icon="icon-cancel"
                        href="javascript:closePwd();">
                        <%=Global.cancel %></a>
            </div>
        </div>
    </div>
</asp:Content>
